<?php

if (is_numeric($_POST['after_id'])) {
	$sort = $db->fetchOne("SELECT sort FROM site_templates WHERE id=?", $_POST['after_id']) + 5;
	$db->insert('site_templates', array('site_id' => $site['id'], 'title' => 'Untitled template', 'sort' => $sort));
	$template_id = $db->lastInsertId();
	header('Content-type: application/json');
	echo json_encode(array('id' => $template_id));
}
